package com.example.conditionBase;

import com.example.conditionBase.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 项目名:springboot-conditionConfig
 * 创建人:贺小五
 * 创建时间:2018/10/18 16:02
 * 类名:SpecialedBeanFactory
 * 类描述:
 */
@Configuration
public class SpecialBeanFactory {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(SpecialBeanFactory.class);

	@Bean
	public A buildA(){
		return new A();
	}
	
	@Bean
	// 如果存在Bean A,则创建Bean B
	@ConditionalOnBean(A.class)
	public B buildB(){
		LOGGER.info("BBBB");
		return new B();
	}

	@Bean
	// 目录下犹如包含E.class 则创建Bean C
	@ConditionalOnClass(E.class)
	public C buildC(){
		return new C();
	}
	
	@Bean
	@ConditionalOnMissingClass(value = "W")
	public D buildD(){
		return new D();
	}
	
	
	@Bean
	// 如果不存在Bean E 那么创建Bean F
	@ConditionalOnMissingBean(E.class)
	public F buildF(){
		return new F();
	}
	
	@Bean
	// 属性文件如果存在 key=hexiaowu value= nan 的则创建BeanH
	@ConditionalOnProperty(value = "hexiaowu",havingValue = "nan")
	public H buildH(){
		return new H();
	}
}
